package my.test.factoryMethodPattern.singletonFactory.lazyLoadFactory;

import java.util.HashMap;
import java.util.Map;

public class ProductFactory {

    private static final Map<String, Product> prMap = new HashMap<>();
    public static synchronized Product createProduct(String type) {
        Product product = null;
        //如果Map中已经有这个对象
        if(prMap.containsKey(type)) {
            product = prMap.get(type);
        } else {
            if(type.equals("Product1")) {
                product = new ConcreateProduct1();
            } else {
                product = new ConcreateProduct2();
            }
            prMap.put(type, product);
        }
        return product;
    }

}
